package com.sys.app.entity.result;

import com.sys.app.entity.emum.ResultEnum;

public class ResultDTO<T> extends AbsResultDTO {
    private T result;

    public ResultDTO() {
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    public static <T> ResultDTO<T> result(ResultEnum code, String message, T result) {
        ResultDTO<T> r = new ResultDTO();
        r.setCode(code.getValue());
        r.setMessage(message);
        r.setResult(result);
        return r;
    }

    public static <T> ResultDTO<T> ok() {
        ResultDTO<T> r = new ResultDTO();
        r.setCode(ResultEnum.SUCCESS.getValue());
        r.setMessage(ResultEnum.SUCCESS.getDesc());
        return r;
    }

    public static <T> ResultDTO<T> error() {
        ResultDTO<T> r = new ResultDTO();
        r.setCode(ResultEnum.ERROR.getValue());
        r.setMessage(ResultEnum.ERROR.getDesc());
        return r;
    }

    public ResultDTO<T> result(T t) {
        this.setResult(t);
        return this;
    }

}
